/////read in counterfactual simulated data

**no behavioreal resopnse
import delimited "$dir/Model/Simulated_data/simulated_data_cfact_movecosts_nob_statcheck.csv", clear
gen uniqid = _n
keep uniqid v26 v14 v24 v22
ren v26 pctile_nob
ren v24 faminc_nob
ren v22 util_nob
tempfile nob
save `nob'

**full behavioral response
import delimited "$dir/Model/Simulated_data/simulated_data_cfact_movecosts_statcheck.csv", clear
gen uniqid = _n
keep uniqid v9 v10 v8
ren v10 pctile_movecost
ren v9 faminc_movecost
ren v8 util_movecost
tempfile movecost
save `movecost'

**decomp 1
import delimited "$dir/Model/Simulated_data/simulated_data_cfact_movecosts_decomp_1_statcheck.csv", clear
gen uniqid = _n
keep uniqid v21 v14 v20
ren v21 pctile_decomp_1
ren v20 faminc_decomp_1
tempfile decomp_1
save `decomp_1'

**decomp 2
import delimited "$dir/Model/Simulated_data/simulated_data_cfact_movecosts_decomp_2_statcheck.csv", clear
gen uniqid = _n
keep uniqid v21 v14 v20
ren v21 pctile_decomp_2
ren v20 faminc_decomp_2
tempfile decomp_2
save `decomp_2'

//baseline
import delimited "$dir/Model/Simulated_data/simulated_data_base_statcheck.csv", clear
gen uniqid = _n

keep uniqid v1 v25 v26 v14 v24 v22
ren v1 statefips
ren v26 pctile
ren v24 faminc
keep if v25<50
ren v22 util

merge 1:1 uniqid using `nob', keep(match) nogen
merge 1:1 uniqid using `movecost', keep(match) nogen
merge 1:1 uniqid using `decomp_1', keep(match) nogen
merge 1:1 uniqid using `decomp_2', keep(match) nogen 
ren v14 weight
collapse (mean) util* pctile* faminc* weight, by(statefips)
save "$temp/cfact_move_data_statcheck", replace



use "$temp/cfact_move_data_statcheck", clear




gen diff_nob_statcheck = pctile_nob - pctile
gen diff_movecost_statcheck = pctile_movecost-pctile
gen diff_decomp_1_statcheck = pctile_decomp_1 - pctile
gen diff_decomp_2_statcheck = pctile_decomp_2 - pctile
keep statefips diff*



merge 1:1 statefips using "$temp/cfact_move_data", keep(match) nogen

gen diff_nob = pctile_nob - pctile
gen diff_movecost = pctile_movecost-pctile
gen diff_decomp_1 = pctile_decomp_1 - pctile
gen diff_decomp_2 = pctile_decomp_2 - pctile
corr diff_movecost*



